#include <mysql/mysql.h>
#include <iostream>

using std::cout; using std::cerr; using std::endl;


int main()
{
  MYSQL* _mysql = mysql_init(NULL);
  if(_mysql == NULL){
    cerr << "init error" << endl; 
    return 0;
  }
  
  /*
  MYSQL* mysql_real_connect(MYSQL* mysql,  // mysql 操作句柄 
                            const char* host, // 服务端ip
                            const char* passwd,  // 用户密码
                            const char* db,   // 数据库
                            size_t port,     // 端口
                            const char* unix_socked  // 本地域套接字
                            unsigned long client_flag   // 数据库标志位
                            )

  */
   
  MYSQL* connect_ret = mysql_real_connect(_mysql,"81.70.77.248", "y","yzh2017","chatNow", 3306, NULL, 0 );
  if(NULL == connect_ret){
    cerr << "connect error" << endl;
    return 0;
  }
  cout << "connect success" <<endl;
  
  char cmd[1024] = "insert into user(userid, nickname,       school, telnum, passwd) value(1, 'jy', 'XPU', '12345',666)";
  int query_ret = mysql_query(_mysql, cmd) ;
  if(0 != query_ret){
    cerr << "exec sql fail:" << cmd <<  endl;
  }

  return 0;
}
